<template>
    <div id="TalentList">
        <body-container>
            <section slot="features">
                <el-button @click="talentDialog.open()">新增发布</el-button>
            </section>
            <search-form-container @search="onSearch">
                <div slot="input" class="search-input-slot">
                    <el-input size="small" clearable class="search-input-slot__cmp" v-model="selectDict.keyWords"
                              placeholder="请输入公司名称"/>
                </div>
                <vj-form hide-foot :form-data.sync="searchForm" inline :cfg-list="searchCfg"/>
            </search-form-container>
            <vj-table :page-obj="pageObj" @loadTable="onSearch" :loading="loading" :cfg-list="cfgList"
                      :table-data="tableData">
                <template #action="row">
                    <text-button text="编辑" @click="talentDialog.open(row)"/>
                    <text-button text="删除" @click="del(row.id)"/>
                </template>
            </vj-table>
        </body-container>
        <talent-dialog @refresh="onSearch()" ref="talentDialog"/>
    </div>
</template>
<script lang="ts">
    import Vue, {ComponentOptions, VueConstructor} from "vue"
    import Component from 'vue-class-component'
    import BodyContainer from "@/components/layout/body-container.vue";
    import SearchFormContainer from "@/components/layout/search-form-conatiner.vue";
    import {Mixins, Ref} from "vue-property-decorator";
    import {TableMixin} from "@/plugins/mixins/table";
    import {requestByDelete, requestByGet, requestByPost} from "@/utils/request";
    import {formatOptions, genTbFmt, groupBy, hookLoading, itemFromArr, updateCfgOption} from "vijay-util";
    import TextButton from "@/components/basic/text-button.vue";
    import {PuzzleRecordTB, TalentTB} from "@/config/table";
    import {PuzzleRecordSH, TalentSH} from "@/config/search";
    import TalentDialog from "@/components/dialog/talent-dialog.vue";
    import {warnConfirm} from "@/utils/logic";

    export const title = "人才列表";
    @Component({
        components: {TalentDialog, TextButton, SearchFormContainer, BodyContainer}
    })
    export default class TalentList extends Mixins(TableMixin) implements ComponentOptions<Vue> {
        name = "TalentList"
        cfgList = TalentTB;
        searchCfg = TalentSH;
        @Ref() talentDialog!: any;
        @hookLoading()
        async onSearch(pageNo?, pageSize?) {
            const params = Object.assign({pageNo,pageSize},this.selectForm,  this.searchForm);
            const res = await requestByGet(`qqc/qqcTalentservice/list`, params);
            this.tableData = res.records;
            return res;
        }
      async del(id) {
        await warnConfirm();
        await requestByDelete(`qqc/qqcTalentservice/delete`, {id});
        this.$message.success("操作成功！");
        return this.onSearch();
      }

      async initOptions(){
            const {records} = await requestByGet(`qqc/qqcPoststype/list`,{pageNo:1,pageSize:999});
            this.searchCfg = updateCfgOption(this.searchCfg,"typeid",formatOptions(records,"name","id"))
            const col= itemFromArr(this.cfgList,"propName","typeid");
            col.formatter = function ({typeid}) {
              const target = records.find(({id})=>+id===+typeid);
              return target&&target.name
            }
        }
        created() {
            this.initOptions();
            this.onSearch();
        }
    }
</script>

<style scoped lang="scss">
    @import "~assets/common.scss";
    @import "~assets/scss/variables.scss";
    #TalentList {
    }
</style>
